< previous page page_505 next page >

Page 505
The Field2Str() Function
The Field2Str() function accepts a variant value (which is whats returned from an ADO recordset). Variant is the only data type that accepts a Null value, so it must be used as the argument in this function. Youll use the IsNull() function to test to see whether the value is Null. If it is, a valid blank string ("") is returned back to the calling procedure. If the value is not Null, the value is then trimmed and returned back to the calling procedure. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Function Field2Str(vntField As Variant) As String
   If IsNull(vntField) Then
      Field2Str = ""
   Else
      Field2Str = Trim$(CStr(vntField))
   End If
End Function
The reason for using the Trim() function is that not all providers will trim the data coming back from the database. For example, if the field is defined as 50 characters in the table, but the data in the field is only 20 characters, some providers return 20 characters and others return 50 characters, using 30 padded spaces after the 20 characters.
The ListFindItem() Procedure
The ListFindItem() procedure is used to search for a value in the ItemData() property in a combo or list box. When the state codes are loaded into the State combo box, the descriptions of the states are placed in the List() property and the state IDs are placed in the ItemData() property. Therefore, when you retrieve the state ID from the employee table, you need to find that state ID in the State combo box by looping through and comparing whats in the ItemData() property with the value you pass to the ListFindItem() procedure. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Sub ListFindItem(ctlAny As Control, lngValue As Long)
   Dim intLoop As Integer
   Dim boolFound As Boolean

   For intLoop = 0 To ctlAny.ListCount - 1
      If ctlAny.ItemData(intLoop) = lngValue Then
         ctlAny.ListIndex = intLoop
         boolFound = True
         intLoop = ctlAny.ListCount

 
< previous page page_505 next page >

If you like this book, buy it!